#
# Classifier for Postfix/Vmailer bounce messages
#
package Mail::Bounce::Compuserve;

use strict;
use vars qw(@ISA $pattern $pattern2);

@ISA = qw(Mail::Bounce::Heuristic);

$pattern = << 'EoF';
${RECIPBLOCK-(?:Receiver not found: \S+\n)+}

Your message could not be delivered as addressed.

--- Message From Postmaster ---

Subject: Addressing CompuServe Mail users

Please contact postmaster@compuserve.com if you need additional formatting
information for other types of addresses.

Cordially,

The Electronic Postmaster

--- Returned Message ---
EoF

sub validate {
    my $self = shift;

    my $keywords = $self->patternmatch($self->bodyhandle->as_string, $pattern);
    return defined($keywords);
}

sub recipients {
    my $self = shift;

    my $keywords = $self->patternmatch($self->bodyhandle->as_string, $pattern);
    if (!$$keywords{RECIPBLOCK}) {
	die "No Recipient block found";
    }
    my @recips = split("\n", $$keywords{RECIPBLOCK});
    if (defined($keywords)) {
	if (wantarray()) {
	    my @res;
	    my $recip;
	    for $recip (@recips) {
		my $res = new Mail::Bounce::Address;
		if ($recip =~ /^Receiver not found: (\S+)/) {
		    $res->type("permfail");
		    $res->action("failed");
		    $res->status("5.1.1 (Unknown user)");
		    $res->final_recipient($1 . "\@compuserve.com");
		    push @res, $res;
		} else {
		    $res->status("5.0.0 (unparsed error)");
		    $res->diagnostic($recip);
		}
	    }
	    return @res;
	} else {
	    return @recips + 0;
	}
    } else {
	die "Compuserve: Unmatched pattern in recipients()\n";
    }
}
1;




